$('#nbxsdForm').tabs({
    border: false,
    onSelect: function (title) {
        if (title == "销售单打印") {
            if (null == $("[name='xsd.id']").val() || $("[name='xsd.id']").val() == '') {
                $.messager.alert('提示', '先保存销售信息，才能打印销售单！', 'info');
                $('#nbxsdForm').tabs('select', "销售信息");
            } else {
                $.ajax({
                    type: "POST",
                    url: $.webPath() + '/xsgl/nbxsd/xsdDetail?xsdId=' + $("input[name='xsd.id']").val(),
                    dataType: "html",
                    beforeSend: function () {
                        $.messager.progress();
                    },
                    success: function (data) {
                        $.messager.progress("close");
                        $('#nbxsddy_xsd_id').html(data);
                        if (data.statusCode == 300) {
                        }
                        if (data.statusCode == 200) {
                        }
                    }
                });
            }
        }
    }
});
//=============按钮事件=============================
//  点击出售联，隐藏出库数量
function nbcslClick(tdName) {
    $("[name='" + tdName + "']").show();
    $("#nbxsddy_ck").hide();
    $("#xsd_csl").show();
    $("#xsd_thd").hide();
    $("#xsd_shd").hide();
}
//点击 提货单，显示出库数量
function nbthdClick(tdName) {
    $("[name='" + tdName + "']").hide();
    $("#nbxsddy_ck").hide();
    $("#xsd_csl").hide();
    $("#xsd_thd").show();
    $("#xsd_shd").hide();
}
//点击   送货单，显示出库数量
function nbshdClick(tdName) {
    $("[name='" + tdName + "']").hide();
    $("#nbxsddy_ck").show();
    // $("#xsddy_tdrq").show();

    $("#xsd_csl").hide();
    $("#xsd_thd").hide();
    $("#xsd_shd").show();
}

// 销售单打印预览
function xsddyPrintPreview() {
    var LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("预览销售单");
    var strBodyStyle = "<style  type=\"text/css\">" +
        ".input-tian{border-top-style:none;border-left-style:none;border-right-style:none;border-bottom-style: 1px solid #57626a;height:22px;line-height:22px;width:100%;color:#485f71;font-weight: bold;background: #F6F9FF;}," +
        " select{display:none}," +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;color:#485f71;}," +
        ".tb th{padding:2px 2px 2px 12px;font-weight:normal;text-align: right;}," +
        ".tb td{padding:2px;},.tb caption{ font-size:24px;height:30px;line-height:30px;}" +
        ".intb{width: 100%;},.intb,.intb th,.intb td{border:1px #57626a solid;}" +
        "</style>";
    var strFormHtml = strBodyStyle + "<body>" + document.getElementById("nbxsddy_print_id").innerHTML + document.getElementById("nbxsddy_xsd_id").innerHTML + document.getElementById("nbxsddy_xia_id").innerHTML + "</body>";
    var nbxsd_xsdh = $("#nbxsd_xsdh").val();
    var nbxsd_ewmtime = $("#nbxsd_ewmtime").val();

    LODOP.ADD_PRINT_HTM(40, 50, 700, 600, strFormHtml);
    LODOP.ADD_PRINT_BARCODE(50, 670, 90, 90, 'QRCode', nbxsd_xsdh + " " + nbxsd_ewmtime);
    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.PREVIEW();
}

//销售单打印
function xsddyPrint() {
    var LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("打印销售单");
    LODOP.SET_PRINT_STYLE("FontSize", 18);

    var inputs = document.getElementById("nbxsddy_id").getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++) {
        inputs[i].setAttribute("value", inputs[i].value);
    }
    var strBodyStyle = "<style type=\"text/css\">" +
        ".input-tian{border-top-style:none;border-left-style:none;border-right-style:none;border-bottom-style: 1px solid #57626a;height:22px;line-height:22px;width:100%;color:#485f71;font-weight: bold;background: #F6F9FF;}," +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;color:#485f71;}," +
        ".tb th{padding:2px 2px 2px 12px;font-weight:normal;text-align: right;}," +
        ".tb td{padding:2px;},.tb caption{ font-size:24px;height:70px;line-height:30px;}" +
        "</style>";
    var strFormHtml = strBodyStyle + "<body>" + document.getElementById("nbxsddy_print_id").innerHTML + document.getElementById("nbxsddy_xsd_id").innerHTML + document.getElementById("nbxsddy_xia_id").innerHTML + "</body>";
    var nbxsd_xsdh = $("#nbxsd_xsdh").val();
    var nbxsd_ewmtime = $("#nbxsd_ewmtime").val();

    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Auto-Width");
    LODOP.ADD_PRINT_HTM(40, 50, 700, 600, strFormHtml);
    LODOP.ADD_PRINT_BARCODE(50, 670, 80, 80, 'QRCode', nbxsd_xsdh + " " + nbxsd_ewmtime);
    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.PRINT();
}


$(function () {
    //加载客户
    $("#xsd_kh_id").jgbmtree($("#xsd_khbm_id"), '', $("#xsd_khbm").val(), '');

    //新增物资计划明细
    $("#nbxsd_xsdmx_toolbar [name='nbxsd_xzxsdmx']").click(function () {
        var thck_id = $("#xsd_thck_id").combobox('getValue');
        var xsgs_id = $("#xsd_xsgs_id").val();
        var sbgs_id = $("#xsd_sbgs_id").val();
        if (thck_id)
            searchkhwindow(xsdmx_searchWindowOKbtnHandler, thck_id,xsgs_id,sbgs_id, null, null);
        else {
            $('#nbxsdForm').tabs('select', "销售信息");
            $.messager.alert("提示", "请选择提货仓库!", "info");
        }
    });
    //删除物资计划明细
    $("#nbxsd_xsdmx_toolbar [name='nbxsd_scxsdmx']").click(function () {
        var rows = $("#nbxsd_mx").edatagrid('getChecked');
        if (rows) {
            $.messager.confirm('提示', '是否确定删除销售单明细?', function (r) {
                if (r) {
                    $.each(rows, function (i, val) {
                        var index = $("#nbxsd_mx").edatagrid('getRowIndex', val);
                        $("#nbxsd_mx").edatagrid('deleteRow', index);
                    });
                    //countSumXsdmx();
                }
            });
        }
        $("#nbxsd_mx").edatagrid('resize');
    });

    //新增合同费用
    $("#nbxsd_xsdfy_toolbar [name='nbxsd_xzxsdfy']").click(function () {
        var data = {
            'sydw.id': null,
            'fylb.id': null,
            'jfsl': 0,
            'dj': 0,
            'je': 0,
            'bz': null
        };
        $("#nbxsd_fy").edatagrid('appendRow', data);
    });
    //删除合同费用
    $("#nbxsd_xsdfy_toolbar [name='nbxsd_scxsdfy']").click(function () {
        var rows = $("#nbxsd_fy").edatagrid('getChecked');
        if (rows) {
            $.messager.confirm('提示', '是否确定删除销售费用?', function (r) {
                if (r) {
                    $.each(rows, function (i, val) {
                        var index = $("#nbxsd_fy").edatagrid('getRowIndex', val);
                        $("#nbxsd_fy").edatagrid('deleteRow', index);
                    });
                }
            });
        }
        $("#nbxsd_fy").edatagrid('resize');
    });


    $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm': 'jzfs'}, function (data) {
        xsdmxGrid($.webPath() + '/xsgl/nbxsd/nbxsd_xsmx?xsdId=' + $("[name='xsd.id']").val() || '', data);
    })

    $.post($.webPath() + '/organ/wls/wlsInuseList', function (jgdata) {
        $.post($.webPath() + '/cwgl/kmys/cyfyys/fylbcombobox', {'gsId': $("#xsd_xsgs_id").val()}, function (data) {
            xsdfyGrid($.webPath() + '/xsgl/nbxsd/nbxsd_xsfy?xsdId=' + $("[name='xsd.id']").val() || '', jgdata, data);
        })
    })
    //发运责任
    $("[name='xsd.fyzr.id']").sjzdcombobox('fyzr', {
        onLoadSuccess: function () {
            if (!$("#xsd_fyzr_id").combobox('getValue'))
                $("[name='xsd.fyzr.id']").val(42)
        }
    });
    //仓库
    $("[name='xsd.thck.id']").ckcombobox($("#xsd_sbgs_id").val());
    //税率
    $('#xsd_sl').slsjzdcombobox("sl");
})

function xsdmxGrid(href, fsOptions) {
    $("#nbxsd_mx").edatagrid({
        url: href,
        fitColumns: false,
        singleSelect: true,
        fit: true,
        checkbox: true,
        checkOnSelect: false,
        selectOnCheck: false,
        rownumbers: true,
        showFooter: true,
        toolbar: "#nbxsd_xsdmx_toolbar",
        frozenColumns: [
            [
                {field: 'checked', checkbox: true},
                {field: 'wzgg.id', title: '物资编码ID', hidden: true},
                {field: 'wzgg.code', title: '物资编码', width: 85},
                {field: 'wzgg.name', title: '物资名称', width: 50},
                {field: 'wzgg.ggxh', title: '规格型号', width: 50},
                {field: 'wzgg.dw', title: '单位', width: 30},
                {field: 'jzfs.id', editor: {type: 'combobox', options: {
                    data: fsOptions,
                    valueField: 'id',
                    textField: 'z',
                    multiple: false,
                    panelHeight: '55'
                }
                }, formatter: function (value) {
                    for (var i = 0; i < fsOptions.length; i++) {
                        if (fsOptions[i].id == value) return fsOptions[i].z;
                    }
                    return value;
                }, title: '记重方式', width: 50}
            ]
        ],
        columns: [
            [
                {field: 'kh.khbm', title: '卡号', editor: {type: 'text'}, width: 130},
                {field: 'xscb', title: '销售成本',
                    formatter: function (value) {
                        var sl = formatJeForHtml(value, ",");
                        return sl;
                    }, width: 70},
                {field: 'js', editor: {type: 'numberbox', options: {min: 0, precision: 0}}, title: '件数',
                    formatter: function (value) {
                        var sl = formatSlForHtml(value, ",");
                        return sl;
                    }, width: 70},
                {field: 'sbsl', editor: {type: 'numberbox', options: {min: 0, precision: 4}}, title: '数量',
                    formatter: function (value) {
                        var sl = formatSlForHtml(value, ",");
                        return sl;
                    }, width: 100},
                {field: 'hsj', editor: {type: 'numberbox', options: {min: 0, precision: 4}}, title: '含税价(元)',
                    formatter: function (value) {
                        var sl = formatJeForHtml(value, ",");
                        return sl;
                    }, width: 100},
                {field: 'hse', editor: {type: 'numberbox', options: {min: 0, precision: 4}}, title: '含税额(元)',
                    formatter: function (value) {
                        var sl = formatJeForHtml2(value, ",");
                        return sl;
                    }, width: 100},
                {field: 'bhsj', editor: {type: 'numberbox', options: {min: 0, precision: 4}}, title: '不含税价(元)',
                    formatter: function (value) {
                        var sl = formatJeForHtml(value, ",");
                        return sl;
                    }, width: 100},
                {field: 'bhse', editor: {type: 'numberbox', options: {min: 0, precision: 4}}, title: '不含税额(元)',
                    formatter: function (value) {
                        var sl = formatJeForHtml2(value, ",");
                        return sl;
                    }, width: 100}
            ]
        ],
        loadFilter: function (data) {
            $.each(data.rows, function () {
                var bhsj = Math.round(this.bhsj * 10000) / 10000;
                var hsj = Math.round(this.hsj * 10000) / 10000;
                var sl = Math.round(this.sbsl * 10000) / 10000;

                if (this.bhsj) {
                    this.bhse = Math.round(multiply(sl, bhsj) * 100) / 100;
                }
                if (this.hsj) {
                    this.hse = Math.round(multiply(sl, hsj) * 100) / 100;
                }
            })
            return data;
        },
        onSelect: function (rowIndex, rowData) {
            //获取每个单元格
            $("#nbxsd_mx").edatagrid('editRow', rowIndex);
            var editors = $("#nbxsd_mx").datagrid('getEditors', rowIndex);
            if (editors.length == 0)
                return;
            var khEditor = editors[1];//申报数量编辑框
            var jsEditor = editors[2];
            var sbslEditor = editors[3];
            var hsjEditor = editors[4];
            var hseEditor = editors[5];
            var bhsjEditor = editors[6];
            var bhseEditor = editors[7];

            sbslEditor.target.unbind("change").bind('change', function () {
                $(sbslEditor.target).numberbox('setValue', $(sbslEditor.target).val());
                changeEidtToSum(rowIndex, jsEditor, sbslEditor, hseEditor, bhseEditor, hsjEditor, bhsjEditor);
            });

            hsjEditor.target.unbind("change").bind('change', function () {
                $(hsjEditor.target).numberbox('setValue', $(hsjEditor.target).val());
                var bhsj = tax.getNotIncludingTaxPrice($(hsjEditor.target).numberbox('getValue'), $("#xsd_sl").combobox('getValue'));
                if (!$(bhsjEditor.target).numberbox('getValue'))
                    $(bhsjEditor.target).numberbox('setValue', bhsj);
                else if (Math.abs($(bhsjEditor.target).numberbox('getValue') - bhsj) >= 0.01) {
                    $(bhsjEditor.target).numberbox('setValue', bhsj);
                }
                changeEidtToSum(rowIndex, jsEditor, sbslEditor, hseEditor, bhseEditor, hsjEditor, bhsjEditor);
            });
            bhsjEditor.target.unbind("change").bind('change', function () {
                $(bhsjEditor.target).numberbox('setValue', $(bhsjEditor.target).val());
                var hsj = tax.getIncludingTaxPrice($(bhsjEditor.target).numberbox('getValue'), $("#xsd_sl").combobox('getValue'));
                if (!$(hsjEditor.target).numberbox('getValue'))
                    $(hsjEditor.target).numberbox('setValue', hsj);
                else if (Math.abs($(hsjEditor.target).numberbox('getValue') - hsj) > 0.01) {
                    $(hsjEditor.target).numberbox('setValue', hsj);
                }
                changeEidtToSum(rowIndex, jsEditor, sbslEditor, hseEditor, bhseEditor, hsjEditor, bhsjEditor);
            });

            //绑定事件——弹出卡号树
            khEditor.target.unbind("dblclick").bind('dblclick', function () {
                var thck_id = $("#xsd_thck_id").combobox('getValue');
                var xsgs_id = $("#xsd_xsgs_id").val();
                var sbgs_id = $("#xsd_sbgs_id").val();
                if (thck_id)
                    searchkhwindow(kh_searchWindowOKbtnHandler, thck_id,xsgs_id,sbgs_id, rowData['cd.id'], rowData['wzgg.id']);
                else {
                    $('#nbxsdForm').tabs('select', "销售信息");
                    $.messager.alert("提示", "请选择提货仓库!", "info");
                }
            });
        },
        onLoadSuccess: function () {
            countSumXsd();
        }
    })
}

//查询物资代码确定按钮回调函数
function xsdmx_searchWindowOKbtnHandler(data) {
    var rowdatas = $.map(data, function (n, i) {
        var wsdj = Math.round(n.wsdj * 10000) / 10000;
        var ll = Math.round((1 + 1.7 / 100) * 10000) / 10000;
        var shuil = Math.round((1 + $("#xsd_sl").combobox('getValue') / 100) * 10000) / 10000;
        var sl = Math.round(n.sl * 1000) / 1000;

        var hsj = Math.round(multiply(multiply(wsdj, ll), shuil) * 10000) / 10000;
        var bhsj = Math.round(multiply(wsdj, ll) * 10000) / 10000;

        return {
            'kh.id': n.id,
            'kh.khbm': n.khbm,
            'wzgg.id': n.jtwz_id,
            'wzgg.oldcode': n.jtwz_oldcode,
            'wzgg.code': n.jtwz_code,
            'wzgg.name': n.jtwz_name,
            'wzgg.ggxh': n.jtwz_ggxh,
            'wzgg.th': n.jtwz_th,
            'wzgg.dw': n.jtwz_dw,
            'cd.id': n.cd_id,
            'cd.z': n.cd_z,
            'kkdsl': Math.round(n.kkdsl * 1000) / 1000,
            'sbsl': sl,
            'xscb': wsdj,
            'hsj': hsj,
            'bhse': formatMoney(multiply(bhsj, sl)),
            'hse': formatMoney(multiply(hsj, sl)),
            'bhsj': bhsj,
            'ck': '',
            'jzfs.id': null
        };
    });
    $.each(rowdatas, function () {
        $("#nbxsd_mx").edatagrid('appendRow', this);
    });
    countSumXsd();
}

function kh_searchWindowOKbtnHandler(data) {
    var row = $("#nbxsd_mx").edatagrid('getSelected');

    var rowdatas = $.map(data, function (n, i) {
        var bhsj = Math.round(row['bhsj'] * 10000) / 10000;
        var hsj = Math.round(row['hsj'] * 10000) / 10000;
        var sl = Math.round(n.sl * 10000) / 10000;
        return {
            'kh.id': n.id,
            'kh.khbm': n.khbm,
            'wzgg.id': row['wzgg.id'],
            'wzgg.oldcode': row['wzgg.oldcode'],
            'wzgg.code': row['wzgg.code'],
            'wzgg.name': row['wzgg.name'],
            'wzgg.ggxh': row['wzgg.ggxh'],
            'wzgg.th': row['wzgg.th'],
            'wzgg.dw': row['wzgg.dw'],
            'cd.id': row['cd.id'],
            'cd.z': row['cd.z'],
            'kkdsl': Math.round(n.kkdsl * 10000) / 10000,
            'sbsl': sl,
            'ck': '',
            'xscb': Math.round(n.wsdj * 10000) / 10000,
            'jzfs.id': row['jzfs.id'],
            'hsj': hsj,
            'bhse': row['bhsj'] ? formatMoney(multiply(bhsj, sl)) : '',
            'hse': row['hsj'] ? formatMoney(multiply(hsj, sl)) : '',
            'bhsj': bhsj
        };
    });

    var index = $("#nbxsd_mx").edatagrid('getRowIndex', row);
    $("#nbxsd_mx").edatagrid('deleteRow', index);

    $.each(rowdatas, function () {
        $("#nbxsd_mx").edatagrid('appendRow', this);
    });
    countSumXsd();
}

function xsdfyGrid(href, jgOptions, fsOptions) {
    $("#nbxsd_fy").edatagrid({
        url: href,
        fitColumns: true,
        singleSelect: true,
        fit: true,
        checkbox: true,
        checkOnSelect: false,
        selectOnCheck: false,
        rownumbers: true,
        toolbar: "#nbxsd_xsdfy_toolbar",
        columns: [
            [
                {field: 'checked', checkbox: true},
                {field: 'sydw.id', editor: {type: 'combobox', options: {
                    data: jgOptions,
                    valueField: 'id',
                    textField: 'qc',
                    multiple: false,
                    panelHeight: '200'
                }
                }, formatter: function (value) {
                    for (var i = 0; i < jgOptions.length; i++) {
                        if (jgOptions[i].id == value) return jgOptions[i].qc;
                    }
                    return value;
                }, title: '收益单位', width: 50},

                {field: 'fylb.id', editor: {type: 'combobox', options: {
                    data: fsOptions,
                    valueField: 'id',
                    textField: 'fykmjc',
                    multiple: false,
                    panelHeight: '110'
                }
                }, formatter: function (value) {
                    for (var i = 0; i < fsOptions.length; i++) {
                        if (fsOptions[i].id == value) return fsOptions[i].fykmjc;
                    }
                    return value;
                }, title: '费用类别', width: 30},
                {field: 'jfsl', editor: {type: 'numberbox', options: {min: 0, groupSeparator: ',', precision: 4}}, title: '计费数量',
                    formatter: function (value) {
                        var sl = formatSlForHtml(value, ",");
                        return sl;
                    }, width: 40},
                {field: 'dj', editor: {type: 'numberbox', options: {min: 0, groupSeparator: ',', precision: 4}}, title: '单价(元)',
                    formatter: function (value) {
                        var sl = formatJeForHtml(value, ",");
                        return sl;
                    }, width: 40},
                {field: 'je', editor: {type: 'numberbox', options: {min: 0, groupSeparator: ',', precision: 2}}, title: '金额(元)',
                    formatter: function (value) {
                        var sl = formatJeForHtml2(value, ",");
                        return sl;
                    }, width: 50},
                {field: 'bz', editor: {type: 'text'}, title: '备注', width: 50}
            ]
        ],
        onSelect: function (rowIndex) {
            //获取每个单元格
            $("#nbxsd_fy").edatagrid('editRow', rowIndex);
            var editors = $("#nbxsd_fy").datagrid('getEditors', rowIndex);
            if (editors.length == 0)
                return;
            var jfslEditor = editors[2];
            var djEditor = editors[3];
            var jeEditor = editors[4];
            jfslEditor.target.unbind("blur").bind('blur', function () {
                $(jfslEditor.target).numberbox('setValue', $(jfslEditor.target).val());
                $(jeEditor.target).numberbox('setValue', $(jfslEditor.target).numberbox('getValue') * $(djEditor.target).numberbox('getValue'));
            });
            djEditor.target.unbind("blur").bind('blur', function () {
                $(djEditor.target).numberbox('setValue', $(djEditor.target).val());
                $(jeEditor.target).numberbox('setValue', $(jfslEditor.target).numberbox('getValue') * $(djEditor.target).numberbox('getValue'));
            });

        }
    })
}

//合计计算
function countSumXsd() {
    var sumxscb = 0;
    var sumjs = 0;
    var sumsbsl = 0;
    var sumhse = 0;
    var sumbhse = 0;
    var data = $("#nbxsd_mx").edatagrid("getData");
    for (var i = 0; i < data.rows.length; i++) {
        var xscb = parseFloat(data.rows[i]["xscb"]);
        var js = parseFloat(data.rows[i]["js"]);
        var sbsl = parseFloat(data.rows[i]["sbsl"]);
        var hse = parseFloat(data.rows[i]["hse"]);
        var bhse = parseFloat(data.rows[i]["bhse"]);
        xscb = isNaN(xscb) ? 0 : xscb;
        js = isNaN(js) ? 0 : js;
        sbsl = isNaN(sbsl) ? 0 : sbsl;
        hse = isNaN(hse) ? 0 : hse;
        bhse = isNaN(bhse) ? 0 : bhse;
        sumxscb += xscb;
        sumjs += js;
        sumsbsl += sbsl;
        sumhse += hse;
        sumbhse += bhse;
    }
    addFooter(sumxscb, sumjs, sumsbsl, sumhse, sumbhse);
}

function addFooter(sumxscb, sumjs, sumsbsl, sumhse, sumbhse) {
    var footer = null;
    footer = [
        {"wzgg.code": "合计", "xscb": formatJe(sumxscb), "js": formatSl(sumjs),
            "sbsl": formatSl(sumsbsl), "hse": formatJe(sumhse), "bhse": formatJe(sumbhse)}
    ];
    if (footer != null)
        $("#nbxsd_mx").edatagrid('reloadFooter', footer);
}

function changeEidtToSum(rowIndex, jsEditor, sbslEditor, hseEditor, bhseEditor, hsjEditor, bhsjEditor) {
    var hsj = Math.round($(hsjEditor.target).val() * 10000) / 10000;
    var sl = Math.round($(sbslEditor.target).val() * 10000) / 10000;
    var bhsj = Math.round($(bhsjEditor.target).numberbox('getValue') * 10000) / 10000;

    $(bhseEditor.target).numberbox('setValue', Math.round(multiply(bhsj, sl) * 100) / 100);
    $(hseEditor.target).numberbox('setValue', Math.round(multiply(hsj, sl) * 100) / 100);
    var js = parseFloat($(jsEditor.target).numberbox('getValue'));
    var hse = parseFloat($(hseEditor.target).numberbox('getValue'));
    var bhse = parseFloat($(bhseEditor.target).numberbox('getValue'));
    js = isNaN(js) ? 0 : js;
    sl = isNaN(sl) ? 0 : sl;
    hse = isNaN(hse) ? 0 : hse;
    bhse = isNaN(bhse) ? 0 : bhse;
    var sumxscb = 0;
    var sumjs = 0;
    var sumsbsl = 0;
    var sumhse = 0;
    var sumbhse = 0;
    var data = $("#xsd_mx").edatagrid("getData");
    for (var i = 0; i < data.rows.length; i++) {
        if (i == rowIndex) {
            var c_xscb = parseFloat(data.rows[i]['xscb']);
            c_xscb = isNaN(c_xscb) ? 0 : c_xscb;
            sumxscb += parseFloat(c_xscb);
            sumjs += parseFloat(js);
            sumsbsl += parseFloat(sl);
            sumhse += parseFloat(hse);
            sumbhse += parseFloat(bhse);
        } else {
            var t_xscb = parseFloat(data.rows[i]['xscb']);
            var t_js = parseFloat(data.rows[i]['js']);
            var t_sbsl = parseFloat(data.rows[i]['sbsl']);
            var t_hse = parseFloat(data.rows[i]['hse']);
            var t_bhse = parseFloat(data.rows[i]['bhse']);
            t_xscb = isNaN(t_xscb) ? 0 : t_xscb;
            t_js = isNaN(t_js) ? 0 : t_js;
            t_sbsl = isNaN(t_sbsl) ? 0 : t_sbsl;
            t_hse = isNaN(t_hse) ? 0 : t_hse;
            t_bhse = isNaN(t_bhse) ? 0 : t_bhse;
            sumxscb += parseFloat(t_xscb);
            sumjs += parseFloat(t_js);
            sumsbsl += parseFloat(t_sbsl);
            sumhse += parseFloat(t_hse);
            sumbhse += parseFloat(t_bhse);
        }
    }
    addFooter(sumxscb, sumjs, sumsbsl, sumhse, sumbhse);
}

